package uinv.com.main;

import java.util.Iterator;
import net.sf.json.JSONObject;
import uinv.com.uitl.readFile;
import uinv.com.uitl.writeFile;
import java.io.File;

public class ChangeManage {

	writeFile wf;

	public static void main(String[] argv) {

		// String fileName = "momodadcv.json";
		String newFileName = "";

		String key;
		String value;

		String version = "{\"VERSIONINFO\":{\"版本\":\"3.0\",\"数据来源\":\"VISIO\",\"来源版本\":\"3.1\"}}";
		JSONObject versionobj = JSONObject.fromObject(version);

		File file = new File(System.getProperty("user.dir"));
		System.out.println("Path:" + file);
		System.out.println("-------------------------");
		File[] tempFile = file.listFiles();
		for (int i = 0; i < tempFile.length; i++) {
			if (tempFile[i].getName().startsWith(".json") || tempFile[i].getName().endsWith(".json")) {

				System.err.println("FileName:" + tempFile[i].getName());
				String[] str = tempFile[i].getName().split(".json");
				newFileName = "new-" + str[0] + ".js";

				JSONObject jsonObject = readFile.readTxtFileIntoStringArrList(tempFile[i].getName());
				Iterator iterator = jsonObject.keys();

				JSONObject jsonObjectNew = new JSONObject();

				while (iterator.hasNext()) {
					key = (String) iterator.next();
					value = jsonObject.getString(key);
					JSONObject valueobj = JSONObject.fromObject(value);
					if (valueobj.get("CLSID") != null) {
						if (valueobj.get("CLSID").equals("IndependentDevice")
								|| valueobj.get("CLSID").equals("independentDevice")
								|| valueobj.get("CLSID").equals("cabinet") || valueobj.get("CLSID").equals("Cabinet")) {
							valueobj.put("_EXTEND_", "");
							jsonObjectNew.put(key, valueobj.toString());
						}
					}
				}
				jsonObjectNew.put("VERSIONINFO", versionobj.get("VERSIONINFO"));
				new writeFile(jsonObjectNew.toString(), newFileName);
			}
		}
	}
}